<template>
    <div id="AsnDetailList">
        <v-tableTitle :btnConfig="btnConfig" :tableSelectData="selectData" @backList="backList"
                      @del="del" @newCreate="newCreate"></v-tableTitle>
        <div class="detail">
            <v-navMenu
                    :detailNav="detailNav"
                    :menuData="menuData"
                    @setMentActive="setMentActive"
                    v-if="detailNav!=1"
            ></v-navMenu>
            <component :data="{detailData,argument}" :is="currentComponent"></component>
        </div>
    </div>

</template>

<script>
    import tableTitle from "commons/TableTitle";
    import navMenu from "commons/NavMenu";
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        name: "DetailList",
        mixins: [baseMixin],
        data() {
            return {
                newFlag: false,
                argument: {},
                detailData: {},
                selectData: [],
                menuData: [
                    {label: this.$t('out.sodetail',{no:1}), index: "2"},
                    {label: this.$t('out.sodetail',{no:2}), index: "3"},
                    {label: this.$t('config.batchProp'), index: "4"},
                    {label: this.$t('out.pickdesc'), index: "5"},
                ],
                detailNav: "1",
                componentConfig: [
                    {
                        name: "Table",
                        label: "table",
                        component: () => import('./page/Table.vue')
                    },
                    {
                        name: "OrderdetailSO1",
                        label: this.$t('out.sodetail',{no:1}),
                        component: () => import('./page/OrderdetailSO1.vue')
                    },
                    {
                        name: "OrderdetailSO2",
                        label: this.$t('out.sodetail',{no:2}),
                        component: () => import('./page/OrderdetailSO2.vue')
                    },
                    {
                        name: "OrderdetailLottable",
                        label: this.$t('config.batchProp'),
                        component: () => import('./page/OrderdetailLottable.vue')
                    },
                    {
                        name: "OrderdetailPick",
                        label: this.$t('out.pickdesc'),
                        component: () => import('./page/OrderdetailPick.vue')
                    },
                ]
            }
        },
        computed: {
            btnConfig() {
                if (this.detailNav == 1) {
                    return [
                        {label: this.$t('common.create'), certigier: this.$parent.newDetailStatus, invalid: "newCreate"},
                        {label: this.$t('common.delete'), certigier: this.$parent.deleteDetailStatus, disabled: true, invalid: "del"},
                    ]
                } else if (this.$store.state.newFlag) {
                    return []
                } else {
                    return [
                        {label: this.$t('common.return'), invalid: "backList"},
                    ]
                }
            },
            currentComponent() {
                return this.componentConfig[this.detailNav - 1].component;
            }
        },
        methods: {
            //删除数据
            async del(data) {
                try {
                    let res = await this.$api.post(`/deleteRtxsodetail`, data);
                    
                        this.$message.success(res.returnMgr);
                        let page = sessionStorage.getItem('page')
                        this.$children[1].getTableData(1, {})
                    
                } catch (e) {
                    this.$message.error(e);
                } finally {
                    this.$children[1].$refs.table.delSelectData(data);
                }
            },
            //选中的数据
            setSelectData(data) {
                this.selectData = data;
            },
            //进入详情
            async setdialog(data) {
                try {
                    let res = await this.$api.post(`/queryOrderSodetailByOrderlinenumber`, {
                        orderkey: this.argument.orderkey,
                        orderlinenumber: data.orderlinenumber
                    });
                    
                        this.detailData = res.bean;
                        this.detailNav = "2";
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            //返回试图
            backList() {
                this.detailNav = "1";
                this.$store.commit("setDetailsNew", false);
            },
            //新建
            async newCreate() {
                this.detailData = {
                    adjustedqty: 0,
                    allocatestrategytype: "1",
                    altsku: " ",
                    cartonbreak: " ",
                    cartongroup: " ",
                    convertedqty: 0,
                    cubicmeter: 0,
                    extendedprice: 0,
                    externlineno: " ",
                    externorderkey: " ",
                    facility: " ",
                    forte_flag: "I",
                    fulfillqty: 0,
                    generatecontainerdetail: "0",
                    hundredweight: 0,
                    id: " ",
                    issubstitute: 0,
                    lot: " ",
                    lottable01: " ",
                    lottable02: " ",
                    lottable03: " ",
                    lottable06: " ",
                    lottable07: " ",
                    lottable08: " ",
                    lottable09: " ",
                    lottable10: " ",
                    manufacturersku: " ",
                    minshippercent: 0,
                    oktosubstitute: 0,
                    openqty: 0,
                    opprequest: "0",
                    oqcautoadjust: "0",
                    oqcrequired: "0",
                    orderlinenumber: "00001",
                    origcaseqty: 0,
                    originalqty: 0,
                    origlayerqty: 0,
                    origpalletqty: 0,
                    packkey: "STD",
                    pallet_id: " ",
                    pickcode: " ",
                    product_cube: 0,
                    product_weight: 0,
                    qtyallocated: 0,
                    qtyintransit: 0,
                    qtypicked: 0,
                    qtypreallocated: 0,
                    qtytoprocess: 1,
                    retailsku: " ",
                    sequence: 0,
                    shelflife: 0,
                    shipgroup01: "N",
                    shipgroup02: "N",
                    shipgroup03: "N",
                    shippedqty: 0,
                    sku: "",
                    skurotation: "Lot",
                    status: "04",
                    storerkey: "",
                    sub_flag: " ",
                    tariffkey: "XXXXXXXXXX",
                    tax01: 0,
                    tax02: 0,
                    unitprice: 0,
                    uom: "EA",
                    updatesource: "0",
                    workorderkey: " ",
                    wpreleased: "0",
                    orderkey: this.argument.orderkey,
                };
                try {
                    let res = await this.$api.get(`/queryOrderSodetailMaxLine/${this.argument.orderkey}`);
                    
                        this.$store.commit("setDetailsNew", true);
                        this.detailData.orderlinenumber = res.bean;
                        this.detailNav = "2";
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            //导航值
            setMentActive(key) {
                this.detailNav = key;
            },

        },
        mounted() {
            this.newFlag = this.$store.state.newFlag;
            if (this.newFlag) {
                this.detailData = {
                    adjustedqty: 0,
                    allocatestrategytype: "1",
                    altsku: " ",
                    cartonbreak: " ",
                    cartongroup: " ",
                    convertedqty: 0,
                    cubicmeter: 0,
                    extendedprice: 0,
                    externlineno: " ",
                    externorderkey: " ",
                    facility: " ",
                    forte_flag: "I",
                    fulfillqty: 0,
                    generatecontainerdetail: "0",
                    hundredweight: 0,
                    id: " ",
                    issubstitute: 0,
                    lot: " ",
                    lottable01: " ",
                    lottable02: " ",
                    lottable03: " ",
                    lottable06: " ",
                    lottable07: " ",
                    lottable08: " ",
                    lottable09: " ",
                    lottable10: " ",
                    manufacturersku: " ",
                    minshippercent: 0,
                    oktosubstitute: 0,
                    openqty: 0,
                    opprequest: "0",
                    oqcautoadjust: "0",
                    oqcrequired: "0",
                    orderlinenumber: "00001",
                    origcaseqty: 0,
                    originalqty: 0,
                    origlayerqty: 0,
                    origpalletqty: 0,
                    packkey: "STD",
                    pallet_id: " ",
                    pickcode: " ",
                    product_cube: 0,
                    product_weight: 0,
                    qtyallocated: 0,
                    qtyintransit: 0,
                    qtypicked: 0,
                    qtypreallocated: 0,
                    qtytoprocess: 1,
                    retailsku: " ",
                    sequence: 0,
                    shelflife: 0,
                    shipgroup01: "N",
                    shipgroup02: "N",
                    shipgroup03: "N",
                    shippedqty: 0,
                    sku: "",
                    skurotation: "Lot",
                    status: "04",
                    storerkey: "",
                    sub_flag: " ",
                    tariffkey: "XXXXXXXXXX",
                    tax01: 0,
                    tax02: 0,
                    unitprice: 0,
                    uom: "EA",
                    updatesource: "0",
                    workorderkey: " ",
                    wpreleased: "0",
                    orderkey: this.$store.state.routeId,
                };
                this.detailNav = "2";
            } else if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                this.argument = data.routeData;
                this.detailData = data.detailList;
                this.detailNav = data.detailListNav;
            } else {
                this.argument = this.$store.state.routeData;
            }

        },
        components: {
            "v-tableTitle": tableTitle,
            "v-navMenu": navMenu,
        },
        watch: {
            detailNav: {
                handler(data) {
                    if (data != "1") {
                        this.$store.commit("setTemporary", true);
                    } else {
                        this.$store.commit("setTemporary", false);
                    }
                },
                immediate: true,
                deep: true
            },
            selectData(data) {
                if (this.$parent.permissionStatus) {
                    if (data.length > 0) {
                        this.$parent.deleteDetailStatus = false;
                    } else {
                        this.$parent.deleteDetailStatus = true;
                    }
                }
            }
        }
    }
</script>

<style>

</style>
